<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%
    String path = request.getContextPath();
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>小贷白名单新增/修改</title>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>
<body>
<form id="mcrWhiteForm">
    <div class="fieldset1 tabel_col tabel_col_s clearFix noBorder">
        <div class="fieldBox col_50">
            <div class="label">业务类型</div>
            <div class="field">
                <select name="busType" id="busType">
                    <option value="0">内部</option>
                    <option value="1">外部</option>
                    <option value="2">物流</option>
                    <option value="3">首付贷</option>
                    <option value="4">车贷分期</option>
                </select>
            </div>
        </div>
        <div class="fieldBox col_50">
            <div class="label">用户类型</div>
            <div class="field">
                <select name="busTypeDtl" id="busTypeDtl">
                    <option value="0">外部纯白用户</option>
                    <option value="1">外部已结清用户</option>
                </select>
            </div>
        </div>
        <div class="fieldBox col_50">
            <div class="label">征信等级</div>
            <div class="field">
                <select name="creditLvl" id="creditLvl">
                    <option value="group01">group01</option>
                    <option value="group02">group02</option>
                    <option value="group03">group03</option>
                    <option value="group04">group04</option>
                    <option value="group05">group05</option>
                    <option value="group06">group06</option>
                    <option value="group07">group07</option>
                    <option value="group08">group08</option>
                    <option value="group09">group09</option>
                    <option value="group10">group10</option>
                </select>
            </div>
        </div>
        <div class="fieldBox col_50">
            <div class="label">单笔金额范围</div>
            <div class="field">
                <select name="singleAmt" id="singleAmt">
                    <option value="1000">1000</option>
                </select>
            </div>
        </div>
        <div class="fieldBox col_50">
            <div class="label">单日最高限额</div>
            <div class="field">
                <select name="dayAmt" id="dayAmt">
                    <option value="1000">1000</option>
                    <option value="10000">10000</option>
                    <option value="20000">20000</option>
                </select>
            </div>
        </div>
        <div class="fieldBox col_50">
            <div class="label">本月最高限额</div>
            <div class="field">
                <select name="mothAmt" id="mothAmt">
                    <option value="1000">1000</option>
                    <option value="5000">5000</option>
                    <option value="10000">10000</option>
                    <option value="20000">20000</option>
                </select>
            </div>
        </div>
        <div class="fieldBox col_50">
            <div class="label">开始有效时间</div>
            <div class="field">
                <input name="startTm" id="startTm" type="text" class="ui-datepicker" value=""/>
            </div>
        </div>
        <div class="fieldBox col_50">
            <div class="label">有效期截止时间</div>
            <div class="field">
                <input name="endTm" id="endTm" type="text" class="ui-datepicker" value=""/>
            </div>
        </div>

    </div>
</form>
<script>
    const whiteId = '${whiteId}';
    $(function () {
        $("#mcrWhiteForm").ligerForm({
            validate: true
        });
        initData();
    });

    //定义父级调用事件
    frameElement.dialog.onOk = function () {
        save();
    }

    frameElement.dialog.onCancel = function () {
        frameElement.dialog.close();
    }

    //保存
    function save() {
        const ligerForm = liger.get("mcrWhiteForm");
        if (!ligerForm.valid()) {
            UIUtils.alertWarning("有验证信息未通过!");
            return;
        }
        const data = ligerForm.getData();
        let url = '<%=path%>/mcr/whiteInspect/add.do';
        if (StringUtils.isNotEmpty(whiteId)) {
            url = '<%=path%>/mcr/whiteInspect/modify.do';
            data["id"] = dataId;
        }
        AjaxUtils.ajaxPost(url, data, addCallback);
    }
    //新增回调
    function addCallback(msg) {
        if (msg.success === 1) {
            parent.grid.reload();
            UIUtils.alertSuccess("操作成功!");
            frameElement.dialog.close();
        } else {
            UIUtils.alertError(msg.info);
        }
    }

    //修改初始化数据
    function initData() {
        if (StringUtils.isEmpty(whiteId)) return;
        const _url = '<%=path%>/mcr/whiteInspect/getById.do';
        AjaxUtils.ajaxGet(_url, {id: dataId}, initCallback);
    }

    //初始化回调
    function initCallback(msg) {
        if (msg.success === 1) {
            setData(msg.data);//设置数据
        } else {
            UIUtils.alertError(msg.info);
        }
    }

    //修改时候设置页面数据
    function setData(data) {
        const form = new liger.get("mcrWhiteForm");
        form.setData({
            busType: data.busType,
            busTypeDtl: data.busTypeDtl,
            creditLvl: data.creditLvl,
            singleAmt: data.singleAmt,
            dayAmt: data.dayAmt,
            mothAmt: data.mothAmt,
            startTm: data.startTm,
            endTm: data.endTm
        });
    }
</script>

</body>
</html>